package com.yanqu.road.server.cmd.activity.xiaowurecall;

import com.yanqu.road.pb.activity.XiaowuRecallProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.xiaowuRecall.XiaowuRecallModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_XIAOWU_RECALL_NEXT_PAGE, desc = "小舞回忆录请求完成页面，领取全部奖励")
public class XiaowuRecallNextPageCmd extends AbstractCommand {

    int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        XiaowuRecallProto.XiaowuNextPageReqMsg reqMsg = XiaowuRecallProto.XiaowuNextPageReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        if (player.getModule(XiaowuRecallModule.class).getUnlockSlice().size() != 15) {
            ret = GameErrorCode.E_XIAOWU_RECALL_PIC_NO_FINISHED;
            return;
        }

        ret = player.getModule(XiaowuRecallModule.class).nextPageGetAllReward();
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            XiaowuRecallProto.XiaowuNextPageRespMsg.Builder respMsg = XiaowuRecallProto.XiaowuNextPageRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_XIAOWU_RECALL_GET_ALL_REWARD_AND_ADD_PAGE, respMsg);
        }
    }
}
